home *** CD-ROM | disk | FTP | other *** search
- { ptext.pas -- Edit and print a text file }
-
- program PText;
-
- uses WinTypes, WinProcs, WObjects, Strings, StdWnds, UPrint;
-
- const
-
- id_Menu = 'FileCommands'; { Menu resource ID }
- cm_FilePrint = 100; { ID for new File:Print command }
- bufSize = 80; { Maximum characters per line }
-
- type
-
- PTextApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- procedure InitInstance; virtual;
- end;
-
- PPTextWindow = ^PTextWindow;
- PTextWindow = object(TFileWindow)
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure CMPrint(var Msg: TMessage);
- virtual cm_First + cm_FilePrint;
- end;
-
-
- { PTextApplication }
-
- {- Initialize PTextApplication object's window }
- procedure PTextApplication.InitMainWindow;
- begin
- MainWindow := New(PPTextWindow, Init(nil, 'Edit and Print Text'))
- end;
-
- {- Initialize each application instance }
- procedure PTextApplication.InitInstance;
- begin
- TApplication.InitInstance;
- if Status = 0 then
- HAccTable := LoadAccelerators(HInstance, 'FileCommands')
- end;
-
-
- { PTextWindow }
-
- {- Construct PTextWindow object }
- constructor PTextWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- var
- Mh: HMenu;
- begin
- TFileWindow.Init(AParent, ATitle, nil);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
- Mh := GetSubMenu(Attr.Menu, 0);
- if Mh <> 0 then
- InsertMenu(Mh, 4, mf_ByPosition or mf_Enabled,
- cm_FilePrint, '&Print')
- end;
-
- {- Print text in editor window }
- procedure PTextWindow.CMPrint(var Msg: TMessage);
- var
- NumLines, LineIndex, Len: Integer;
- Buffer: PChar;
- begin
- LineIndex := 0;
- NumLines := Editor^.GetNumLines;
- if (NumLines > 0) and PrnStart('PText') then
- begin
- while LineIndex < NumLines do
- begin
- Len := Editor^.GetLineLength(LineIndex) + 1;
- GetMem(Buffer, Len);
- if Len > 1 then
- Editor^.GetLine(Buffer, Len, LineIndex)
- else
- Buffer^ := #0;
- PrnLine(Buffer);
- Inc(LineIndex);
- FreeMem(Buffer, Len)
- end;
- PrnStop
- end
- end;
-
- var
-
- PTextApp: PTextApplication;
-
- begin
- PTextApp.Init('PTextApp');
- PTextApp.Run;
- PTextApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/16/1991
- ---------------------------------------------------------------}
-